import 'package:cbec_app/components/base/base_icon.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/routes/routes.dart';
import 'package:cbec_app/utils/ThemeConfig.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class ConsigneeInfo extends StatefulWidget {
  ///是否为默认地址
  final bool isDefault;

  ///联系人姓名
  final String receiveName;

  ///联系人电话
  final String receiveMobile;

  ///联系人省市区
  final String receiveAddress;

  ///联系人地址
  final String receiveInfo;

  ///编辑按钮类型
  final EditBtnType btnType;

  ///操作按钮垂直对齐方式
  final CrossAxisAlignment alignment;

  final bool isCanTap;

  ///收货人信息
  const ConsigneeInfo({
    super.key,
    this.isDefault = false,
    this.btnType = EditBtnType.modify,
    this.alignment = CrossAxisAlignment.start,
    this.isCanTap = true,
    required this.receiveName,
    required this.receiveMobile,
    required this.receiveAddress,
    required this.receiveInfo,
  });

  @override
  State<StatefulWidget> createState() {
    return _ConsigneeInfoState();
  }
}

class _ConsigneeInfoState extends State<ConsigneeInfo> {
  @override
  Widget build(BuildContext context) {
    return BaseInteractive(
      childWidget: Container(
        decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(8.h))),
        child: Padding(
          padding: EdgeInsets.all(10.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: widget.alignment,
            children: [
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      widget.isDefault
                          ? Container(
                              padding: EdgeInsets.only(left: 4.w, right: 4.w, top: 2.h, bottom: 2.h),
                              margin: EdgeInsets.only(right: 8.w),
                              decoration: BoxDecoration(color: ThemeConfig.themeColor),
                              child: Text(
                                '默认',
                                style: setTextStyle(11, FontWeight.w400, Colors.white),
                              ),
                            )
                          : emptyWidget(),
                      const BaseIcon(
                        url: 'location.png',
                        size: 14,
                      ),
                      Container(
                        margin: EdgeInsets.only(left: 1.w),
                        child: Text(
                          widget.receiveName != '' ? widget.receiveName : '请添加收货地址',
                          style: setTextStyle(12, FontWeight.w400, ThemeConfig.mainTextColor),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(left: 8.w),
                        child: Text(
                          widget.receiveMobile,
                          style: setTextStyle(12, FontWeight.w400, ThemeConfig.subTextColor),
                        ),
                      )
                    ],
                  ),
                  widget.receiveName != ''
                      ? Container(
                          width: 264.w,
                          margin: const EdgeInsets.only(top: 10),
                          child: Text(
                            "${widget.receiveAddress}${widget.receiveInfo}",
                            style: setTextStyle(12, FontWeight.w400, ThemeConfig.subTextColor),
                          ),
                        )
                      : emptyWidget()
                ],
              ),
              _getBtn()
            ],
          ),
        ),
      ),
      onClick: widget.isCanTap == true
          ? () {
              dealBtnClick();
            }
          : null,
    );
  }

  ///按钮事件处理
  void dealBtnClick() {
    switch (widget.btnType) {
      case EditBtnType.select:
      default:
        Get.toNamed('${Routes.address}?isSelect=true');
        break;
    }
  }

  ///获取操作按钮
  Widget _getBtn() {
    switch (widget.btnType) {
      case EditBtnType.modify:
        //Get.toNamed('${Routes.address}?isSelect=true');
        return Container(
          width: 57.w,
          height: 28.h,
          alignment: Alignment.center,
          decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(48.h)), border: Border.all(color: Color(0xffd7d7d7))),
          child: Text(
            '修改',
            style: setTextStyle(12, FontWeight.w500, ThemeConfig.mainTextColor),
          ),
        );
      case EditBtnType.select:
        return const Icon(Icons.navigate_next);

      case EditBtnType.none:
        return emptyWidget();
    }
  }
}

///编辑按钮类型
enum EditBtnType {
  ///修改按钮
  modify,

  ///选择按钮
  select,

  ///不显示按钮
  none
}
